Repository navigation
chainntnfs/btcdnotify: scan the chain for historical spends - #11583
Open
eynhaender wants to merge 3 commits into
Open
eynhaender wants to merge 3 commits into
eynhaender wants to merge 3 commits into
Conversation
RegisterSpendNtfn issued the btcd rescan command, which rpcclient marks as deprecated, to find a spend below the current height. Dispatch the historical spend request to the notification dispatcher instead, which scans the blocks of the requested range from the end height down to the start height and matches each transaction against the request, as the bitcoind notifier does. The outpoint case keeps its existing shortcuts: an unspent output completes the request at once, and a spent output starts the scan at the height of its funding block. The dispatcher now always updates the spend details once the scan finishes, including when no spend was found. Previously an output script request whose rescan found no spend left the request pending, so its spend hint was never committed and the historical dispatch was repeated from the original height hint on every restart. This also allows btcd-compatible servers that do not implement the deprecated rescan command, such as libbitcoin-server, to serve as a chain backend.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
RegisterSpendNtfnof the btcd notifier used the deprecated btcdrescancommand (RescanAsync) for historical spends. The historical spend dispatch now runs in the notification dispatcher, as the bitcoind notifier does: it scans the blocks of the range from the end height down (getblockhash,getblock) and matches each transaction withSpendRequest.MatchesTx. The outpoint shortcuts are kept: an unspent output completes the request at once,and a spent output starts the scan at its funding height.
The dispatch now always updates the spend details, also when no spend was found. Before, an output script request without a spend stayed pending, so its spend hint was never committed and the scan repeated from the original height
hint on every restart, also with btcd.
This lets btcd-compatible servers without
rescan, such as libbitcoin-server, serve as a chain backend. There, every historical spend dispatch failed and the spend was never notified. lnd no longer usesrescan.Related: btcsuite/btcwallet#1515 removes the wallet's use of
rescan. The two changes are independent.Verification
TestHistoricalSpendDetails: unspent, spent and out-of-range requests, by outpoint and by script.TestHistoricalSpendDispatchUnspent: the spend hint of an unspent output script is committed. Fails on master against btcd, passes with this change.chainntnfsinterface tests (btcd): 30/30, same as master.make itest backend=btcd(384 cases): identical to master, 545 passed, 9 skipped. 812 historical spend scans completed, 99 found a spend, none failed.